package com.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.entity.CardMedicine;
import com.demo.mapper.CardMedicineMapper;
import com.demo.service.CardMedicineService;
import org.springframework.stereotype.Service;
import com.demo.util.MyPage;

import javax.annotation.Resource;

/**
 * (CardMedicine)表服务实现类
 *
 * @author Sakura
 * @since 2023-11-26 17:07:05
 */
@Service("cardMedicineService")
public class CardMedicineServiceImpl extends ServiceImpl<CardMedicineMapper, CardMedicine> implements CardMedicineService {
    @Resource
    private CardMedicineMapper cardMedicineMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CardMedicine queryById(Long id) {
        return this.cardMedicineMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pageNo    当前页
     * @param pageSize  数据大小
     * @param searchKey 查询关键字
     * @return 查询结果
     */
    @Override
    public MyPage<CardMedicine> queryByPage(Integer pageNo, Integer pageSize, String searchKey) {
        long total = this.cardMedicineMapper.count(searchKey);
        int start = (pageNo - 1) * pageSize;
        return new MyPage<CardMedicine>(this.cardMedicineMapper.queryPage(start, pageSize, searchKey), total);
    }


    /**
     * 修改数据
     *
     * @param cardMedicine 实例对象
     * @return 实例对象
     */


    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.cardMedicineMapper.deleteById(id) > 0;
    }

    @Override
    public int updateSum(Long id, Integer sum) {
        return cardMedicineMapper.updateSum(id, sum);
    }

    @Override
    public boolean updateAll(Integer selected) {
        return cardMedicineMapper.updateAll(selected);
    }
}
